<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$item=$this->plugin_setting('sale_yao');
	$item['title']=$item['title']?:'邀请奖任务';
	$item['desc']=$item['desc']?:'邀请奖任务！邀请好友赚余额！';
	$item['action']='jy_weishop/sale.yao/';
	$item['url']=custom_url('jy_weishop/sale.yao/',true);
	$item['yao_set2']=$item['yao_set'];
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'set',
		'desc'=>'邀请奖任务设置',
		'edit'=>array(
			array('type'=>'ewm','name'=>'url','title'=>'邀请奖任务入口'),
			array('type'=>'copy','name'=>'url','title'=>'邀请奖任务长链'),
			array('type'=>'copy','name'=>'action','title'=>'邀请奖任务短链'),
			array('type'=>'switch','name'=>'isopen','title'=>'开启邀请有奖','help'=>'邀请指定分销等级，达多少人获得奖励'),
			array('name'=>'levels','title'=>'限制会员等级参与','type'=>'checkbox','options'=>'levels','help'=>'留空，不限制！'),
			array('type'=>'string','name'=>'title','title'=>'标题'),
			array('type'=>'string','name'=>'desc','title'=>'描述'),
			array('type'=>'unitstring','unit'=>'天','name'=>'yao_days','title'=>'任务有效期','help'=>'留空不生效：激活后，需在N天内完成任务，才有奖励！'),
			array('type'=>'unitstring','unit'=>'天','name'=>'yao_leveldays','title'=>'邀请人升级有效期','help'=>'留空不生效：邀请人，需在N天内（会员注册时间开始计时）到底邀请等级，才有奖励！'),
			array('type'=>'radio','title'=>'指定奖励类型','name'=>'yao_feetype','options'=>'yao_feetypes','help'=>'默认是邀请得佣金！'),
			array('type'=>'array','name'=>'yao_set','title'=>'商城会员邀请奖','show'=>array('yao_feetype <'=>10),'add_tip'=>'添加一个商城会员邀请奖',
									'list'=>array(
										array('name'=>'level_id','title'=>'邀请等级','type'=>'select','help'=>'','options'=>'shoplevels'),
										array('type'=>'radio','title'=>'计算规则','name'=>'yao_jitype','options'=>'yao_jitype'),
										array('type'=>'string','name'=>'num','title'=>'邀请人数','show'=>array('yao_jitype'=>0)),
										array('type'=>'string','name'=>'fee','title'=>'奖励'),							
									),
									'details'=>array(
										array('name'=>'level_id','title'=>'邀请等级','type'=>'select','help'=>'','options'=>'shoplevels'),
										array('type'=>'radio','title'=>'计算规则','name'=>'yao_jitype','options'=>'yao_jitype','help'=>'[阶梯式]：达到指定人数，奖励一次（每阶梯只奖励一次）！[每人式]：每邀请某等级的下线得一次奖励'),
										array('type'=>'unitstring','unit'=>'人','name'=>'num','title'=>'邀请人数','show'=>array('yao_jitype'=>0)),
										array('type'=>'unitstring','unit'=>'元','name'=>'fee','title'=>'奖励'),	
									)
			),
			array('type'=>'array','name'=>'yao_set2','title'=>'商城会员邀请奖','show'=>array('yao_feetype'=>10),'add_tip'=>'添加一个商城会员邀请奖',
									'list'=>array(
										array('name'=>'level_id','title'=>'邀请等级','type'=>'select','help'=>'','options'=>'shoplevels'),
										array('type'=>'radio','title'=>'计算规则','name'=>'yao_jitype','options'=>'yao_jitype'),
										array('type'=>'string','name'=>'num','title'=>'邀请人数','show'=>array('yao_jitype'=>0)),
										array('name'=>'couponid','title'=>'优惠券','type'=>'select','help'=>'','options'=>'coupons'),
										array('type'=>'unitstring','unit'=>'张','name'=>'fee','title'=>'奖励优惠券'),						
									),
									'details'=>array(
										array('name'=>'level_id','title'=>'邀请等级','type'=>'select','help'=>'','options'=>'shoplevels'),
										array('type'=>'radio','title'=>'计算规则','name'=>'yao_jitype','options'=>'yao_jitype','help'=>'[阶梯式]：达到指定人数，奖励一次（每阶梯只奖励一次）！[每人式]：每邀请某等级的下线得一次奖励'),
										array('type'=>'unitstring','unit'=>'人','name'=>'num','title'=>'邀请人数','show'=>array('yao_jitype'=>0)),
										array('name'=>'couponid','title'=>'优惠券','type'=>'select','help'=>'','options'=>'coupons'),
										array('type'=>'unitstring','unit'=>'张','name'=>'fee','title'=>'奖励优惠券'),	
									)
			),
			array('type'=>'image','name'=>'adimgtop','title'=>'任务首图'),
			array('type'=>'image','name'=>'adimg','title'=>'底部活动宣传图'),
			array('type'=>'richtext','name'=>'xieyi','title'=>'活动规则'),
		)
	);
	$return['yao_feetypes']=$this->credit_type;
	$return['yao_feetypes'][0]='佣金';
	$return['yao_feetypes'][10]='优惠券';
	$return['yao_jitype']=array('0'=>'阶梯式','1'=>'每人式');
	$return['shoplevels']=pdo_getall('jy_weishop_member_level',array('merchid'=>0,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['shoplevels']['0']=array('id'=>0,'title'=>'默认等级');
	$return['levels']=array();
	foreach($return['shoplevels'] as $lv){
		$return['levels'][$lv['id']]=$lv['title'];
	}
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='set'){
	$post=get_postdata();
	if($post['yao_feetype']==10){
		$post['yao_set']=$post['yao_set2'];
	}
	$this->plugin_setting('sale_yao',$post);
	exi('设置成功');
}